﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace PS.WSSDeploy.Package.Test.Config
{
    [Serializable]
    public class Config
    {
        public string Name { get; set; }
        public string ServerName { get; set; }
        public string ServicePort { get; set; }
        private string _sandboxSiteUrl;
        public string SandboxSiteUrl
        {
            get { return _sandboxSiteUrl; }
            set
            {
                var uri = new Uri(value);
                ServerName = uri.Host;
                _sandboxSiteUrl = value;
            }
        }

        public bool WspContainsResources { get; set; }
        public bool UseTargetPath { get; set; }
        public string RemoteDebuggerLogin { get; set; }
        public byte[] RemoteDebuggerPassword { get; set; }
        public bool RecycleAppPoolsBeforeCopyToGac { get; set; }
        public bool UseCertificate { get; set; }
        public string CertificateFileName { get; set; }
        public byte[] CertificateFilePassword { get; set; }
        public string IdentityDnsName { get; set; }
        [XmlElement(typeof(WebAppItem), ElementName = "WepApp")]
        public List<WebAppItem> WebApps { get; set; }

        public Config()
        {
            ServerName = string.Empty;
            ServicePort = "9000";
            WspContainsResources = true;
            UseTargetPath = true;
            RecycleAppPoolsBeforeCopyToGac = true;
            UseCertificate = false;
            CertificateFileName = string.Empty;
            IdentityDnsName = string.Empty;
            WebApps = new List<WebAppItem>();
        }

        public string GetRemoteDebuggerPassword()
        {
            if (RemoteDebuggerPassword == null)
                return string.Empty;

            string retVal = "";
            //string retVal = Crypto.DecryptStringFromBytes_AES(RemoteDebuggerPassword, ConfigContainer.key, ConfigContainer.iv);
            return string.IsNullOrEmpty(retVal) ? string.Empty : retVal;
        }

        public void SetRemoteDebuggerPassword(string str)
        {
            byte[] encrypted = new byte[] {};
            //byte[] encrypted = string.IsNullOrEmpty(str) ? null : Crypto.EncryptStringToBytes_AES(str, ConfigContainer.key, ConfigContainer.iv);
            RemoteDebuggerPassword = encrypted;
        }

        public string GetCertificateFilePassword()
        {
            if (CertificateFilePassword == null)
                return string.Empty;

            string retVal = "";
            //string retVal = Crypto.DecryptStringFromBytes_AES(CertificateFilePassword, ConfigContainer.key, ConfigContainer.iv);
            return string.IsNullOrEmpty(retVal) ? string.Empty : retVal;
        }

        public void SetCertificateFilePassword(string str)
        {
            //byte[] encrypted = string.IsNullOrEmpty(str) ? null : Crypto.EncryptStringToBytes_AES(str, ConfigContainer.key, ConfigContainer.iv);
            //CertificateFilePassword = encrypted;
        }
    }
}
